package com.asset.dispoal.business.bsAgreement.service.commom;

import com.asset.dispoal.business.bsAgreement.domain.db.entity.Agreement;
import com.asset.dispoal.business.bsAgreement.domain.db.mapper.AgreementMapper;
import com.asset.dispoal.business.bsAgreement.dto.AgreementRequest;
import com.asset.dispoal.business.bsAgreement.dto.AgreementResponse;
import com.asset.dispoal.business.bsAgreement.service.converter.AgreementConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;

import java.util.List;

/**
 * @author qr
 * @date 2022/4/12$
 */
@Component
public class QueryAgreementCommand implements BaseCommand<AgreementRequest, Result<List<AgreementResponse>>> {

    @Autowired
    AgreementMapper agreementMapper;

    @Override
    public Result<List<AgreementResponse>> execute(AgreementRequest request) {
        Agreement agreement = AgreementConverter.INSTANCE.reqToDo(request);
        List<Agreement> agreements = agreementMapper.queryAgreement(agreement);
        List<AgreementResponse> agreementResponses = AgreementConverter.INSTANCE.dosToRes(agreements);
        return Result.ok(agreementResponses);
    }
}
